package com.lai.note.util;

import android.content.Context;

import com.lai.note.dto.ResponseResult;
import com.lai.note.service.UserBaseService;

import java.util.Date;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class TokenUtil {

    public static String userToken;

    public static void getToken(Context context){
        Retrofit retrofit = RetrofitRequest.getInstance(context);
        UserBaseService userBaseService = retrofit.create(UserBaseService.class);
        Call<ResponseResult> call = userBaseService.getToken(1,new Date().toString());
        call.enqueue(new Callback<ResponseResult>() {
            @Override
            public void onResponse(Call<ResponseResult> call, Response<ResponseResult> response) {
                ResponseResult res = response.body();
                if(res.getStatus()==200){
                    System.out.println("res.getData:-->"+res.getData());
                    userToken = res.getData().toString();
                }
            }

            @Override
            public void onFailure(Call<ResponseResult> call, Throwable t) {
                t.printStackTrace();
            }
        });
        System.out.println("userToken:-->"+userToken);
    }

}
